import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
import './assets/css/global.css'
Vue.config.productionTip = false
// 导入axios
import axios from 'axios'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import config from './config'

Vue.prototype.defaults_url = config.baseUrl

// 配置请求根路径
axios.defaults.baseURL = config.baseUrl

axios.interceptors.request.use(config => {
  NProgress.start()
  let token = window.sessionStorage.getItem("token") || null
  config.headers.Authorization = token
  return config
})
// 在response 拦截器中，展示进度条 NProgress.dome()
axios.interceptors.response.use(config => {
  NProgress.done()
  return config
})
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
// axios.defaults.headers.delete['Content-Type'] = 'application/x-www-form-urlencoded';
// axios.defaults.headers.get['Content-Type'] = 'application/x-www-form-urlencoded';
//转换成form的方法  key=value
axios.defaults.transformRequest = [function (data) {
  let ret = ''
  for (let it in data) {
    ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
  }
  return ret
}]
// 挂载在全局中
Vue.prototype.$http = axios




new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
